package core;

import java.util.Random;

public class Weapon extends Element {
	/* Starting strength */
	private static final int START_STR = 1;
	/* Maximum strength */
	private static final int MAX_STR = 99;
	/* Starting accuracy */
	private static final double START_ACC = 0.5;
	/* Maximum accuracy */
	private static final double MAX_ACC = 0.95;

	private int currentSTR;
	private double acc;

	public Weapon() {
		super();
		currentSTR = START_STR;
		acc = START_ACC;
	}

	public int getCurrentSTR() {
		return currentSTR;
	}

	public void setCurrentSTR(int currentSTR) {
		if (currentSTR <= MAX_STR)
			this.currentSTR = currentSTR;
	}

	public double getAcc() {
		return acc;
	}

	public void setAcc(double acc) {
		if (acc <= MAX_ACC)
			this.acc = acc;
	}

	public void levelUp() {
		intLevelUp();
	}

	public int hit() {
		return intHit();
	}

	/* When leveling up, the strength is increased by 2 and the accuracy by 0.01 */
	private void intLevelUp() {
		if ((currentSTR + 2 <= MAX_STR) && (acc + 0.01 <= MAX_ACC)) {
			currentSTR += 2;
			acc += 0.01;
		}
	}

	/* Checking if it will hit or not */
	private int intHit() {
		Random rand = new Random();
		double i = rand.nextDouble();
		if (i < acc) {
			return currentSTR;
		} else
			return 0;
	}
}
